<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 9/22/17
 * Time: 10:46 AM
 */

namespace api\modules\osc\controllers;


use common\components\ocr\baidu\AipOcr;
use common\components\ocr\baidu\AipBase;
use common\components\ocr\Config;
use common\components\ocr\ImagePlusPlus;
use common\components\tools\Tools;
use wodrow\yii\rest\Controller;
use yii\httpclient\Client;

class BusinessController extends Controller
{
    /**
     * 测试
     * @desc 测试
     */
    public function actionTest($image_url = null)
    {
        $client = new AipOcr(Config::$baidu['api_id'], Config::$baidu['api_key'], Config::$baidu['api_secret']);
        $result = $client->basicGeneral($image_url);
        return $result;
    }
    /*public function actionTest($image_url = null)
    {
        $data = [
            'api_key' => Config::$image_plus_plus['api_key'],
            'api_secret' => Config::$image_plus_plus['api_secret'],
        ];
        if ($image_url)$data['url'] = $image_url;
        $data['type'] = ImagePlusPlus::TYPE_TEXT;
        $client = new Client();
        $response = $client->createRequest()
            ->setMethod('post')
            ->setUrl(Config::$image_plus_plus['url'])
            ->setData($data)
            ->send();
        $x = json_decode($response->content);
        return $x;
    }*/
    /*public function actionTest($url, $image_url = null, $image_url1 = null, $image_url2 = null)
    {
        $data = [
            'api_key' => Config::$face_plus_plus['api_key'],
            'api_secret' => Config::$face_plus_plus['api_secret'],
//                'return_landmark' => 1, // 是否检测并返回人脸关键点 默认值为 0
//                'return_attributes' => "none", // 是否检测并返回根据人脸特征判断出的年龄、性别、情绪等属性 默认值为 none
//                'calculate_all' => 1, // 是否检测并返回所有人脸的人脸关键点和人脸属性。如果不使用此功能，则本 API 只会对人脸面积最大的五个人脸分析人脸关键点和人脸属性 默认值为 0
        ];
        if ($image_url)$data['image_url'] = $image_url;
        if ($image_url1)$data['image_url1'] = $image_url1;
        if ($image_url2)$data['image_url2'] = $image_url2;
//        var_dump($data);exit;
        $client = new Client();
        $response = $client->createRequest()
            ->setMethod('post')
            ->setUrl($url)
            ->setData($data)
            ->send();
//        var_dump($response->content);exit;
        $x = json_decode($response->content);
//        $x = Tools::objectToArray($response->content);
        return $x;
    }*/
}